#include "CheckingAccount.hh"
#include "IDGenerator.hh"  // 引入ID生成器
using namespace std;

CheckingAccount::CheckingAccount(Customer* owner) : Account(IDGenerator::generateAccountID(false), owner) {
    // 调用基类构造函数，通过IDGenerator生成账户ID
}


bool CheckingAccount::deposit(double amount, const string& note) {
    if (amount <= 0) {
        cout << "Invalid deposit amount.\n";
        return false;
    }
    balance += amount;
    addTransaction(make_shared<Transaction>("DEPOSIT", amount, nullptr, this, note));
    return true;
}

bool CheckingAccount::withdraw(double amount, const string& note) {
    if (amount <= 0 || amount > balance) {
        cout << "Invalid or insufficient funds for withdrawal.\n";
        return false;
    }
    balance -= amount;
    addTransaction(make_shared<Transaction>("WITHDRAW", amount, this, nullptr, note));
    return true;
}

bool CheckingAccount::transfer(Account* to, double amount, const string& note) {
    if (amount <= 0 || amount > balance) {
        cout << "Invalid or insufficient funds for transfer.\n";
        return false;
    }
    balance -= amount;
    addTransaction(make_shared<Transaction>("TRANSFER_OUT", amount, this, to, note));
    to->deposit(amount, note);
    return true;
}

void CheckingAccount::getInfo() const {
    cout << "Checking Account: " << accountID << " | Balance: ¥" << balance << "\n";
}

string CheckingAccount::getAccountType() const {
    return "Checking Account";
}